home *** CD-ROM | disk | FTP | other *** search
- % File: prheader.ps
- % Copyright (c) 1988, Miguel Santana, miguel@imag.imag.fr
- % Based on header.ps file from a2ps package
-
- % General macros.
- /xdef {exch def} bind def
- /getfont {exch findfont exch scalefont} bind def
-
- % Page description variables and inch function are defined by a2ps program.
-
- % Character size for differents fonts.
- landscape
- { /filenamefontsize 12 def }
- { /filenamefontsize 16 def }
- ifelse
- /datefontsize filenamefontsize 0.8 mul def
- /headermargin filenamefontsize 0.25 mul def
- /bodymargin bodyfontsize 0.7 mul def
-
- % Font assignment to differents kinds of "objects"
- /filenamefontname /Helvetica-Bold def
- /stdfilenamefont filenamefontname filenamefontsize getfont def
- /datefont /Helvetica datefontsize getfont def
- /bodyfont /Courier bodyfontsize getfont def
-
- % Logical page attributs (a half of a real page or sheet).
- /pagewidth
- bodyfont setfont (0) stringwidth pop columns mul bodymargin dup add add
- def
- /pageheight
- bodyfontsize lines mul bodymargin dup add add headersize add
- def
-
- % Coordinates for upper corner of a logical page and for sheet number.
- % Coordinates depend on format mode used.
- % In twinpage mode, coordinate x of upper corner is not the same for left
- % and right pages: upperx is an array of two elements, indexed by sheetside.
- /rightmargin margin 3 div def
- /leftmargin margin 2 mul 3 div def
- /topmargin margin twinpage {3} {2} ifelse div def
- landscape
- { % Landscape format
- /uppery rightmargin pageheight add bodymargin add def
- /sheetnumbery sheetwidth leftmargin pageheight add datefontsize add sub def
- twinpage
- { % Two logical pages
- /upperx [ topmargin % upperx for left page
- dup pagewidth add % upperx for right page
- ] def
- /sheetnumberx sheetheight topmargin sub def
- }
- { /upperx [ topmargin dup ] def
- /sheetnumberx sheetheight topmargin sub datefontsize sub def
- }
- ifelse
- }
- { % Portrait format
- /uppery topmargin pageheight add def
- /upperx [ leftmargin dup ] def
- /sheetnumberx sheetwidth rightmargin sub datefontsize sub def
- /sheetnumbery
- sheetheight
- topmargin pageheight add datefontsize add headermargin add
- sub
- def
-
- }
- ifelse
-
- % Strings used to make easy printing numbers
- /pnum 12 string def
- /empty 12 string def
-
- % Other initializations.
- /datewidth date stringwidth pop def
- /filenameroom
- pagewidth
- filenamefontsize 4 mul datewidth add (Page 999) stringwidth pop add
- sub
- def
-
-
- % Function newfile: init file name and reset page number for each new file.
- /newfile
- { cleanup
- /filename xdef
- /filenamewidth filename stringwidth pop def
- /filenamefont
- filenamewidth filenameroom gt
- {
- filenamefontname
- filenamefontsize filenameroom mul filenamewidth div
- getfont
- }
- { stdfilenamefont }
- ifelse
- def
- } bind def
-
- % Function printpage: Print a physical page.
- /printpage
- { /sheetside 0 def
- twinpage noheader and
- { sheetnumber }
- if
- showpage
- % pagesave restore
- /sheet sheet 1 add def
- } bind def
-
- % Function cleanup: terminates printing, flushing last page if necessary.
- /cleanup
- { twinpage sheetside 1 eq and
- { printpage }
- if
- } bind def
-
- %
- % Function startpage: prints page header and page border and initializes
- % printing of the file lines.
- /startpage
- { sheetside 0 eq
- { % /pagesave save def
- landscape
- { sheetwidth 0 inch translate % new coordinates system origin
- 90 rotate % landscape format
- } if
- } if
- noheader not { printheader } if
- upperx sheetside get bodymargin add
- uppery
- bodymargin bodyfontsize add noheader {0} {headersize} ifelse add
- sub
- moveto
- bodyfont setfont
- } bind def
-
- % Function printheader: prints page header.
- /printheader
- { upperx sheetside get uppery headersize sub 1 add moveto
- datefont setfont
- gsave
- datefontsize headermargin rmoveto
- date show % date/hour
- grestore
- gsave
- pagenum pnum cvs pop
- pagewidth (Page 999) stringwidth pop sub
- headermargin
- rmoveto
- (Page ) show pnum show % page number
- grestore
- empty pnum copy pop
- gsave
- filenamefont setfont
- filenameroom filename stringwidth pop sub 2 div datewidth add
- bodymargin 2 mul
- add
- headermargin
- rmoveto
- filename show % file name
- grestore
- } bind def
-
- %
- % Function endpage: adds a sheet number to the page (footnote) and prints
- % the formatted page (physical impression). Activated at the end of each
- % source page (lines reached or FF character).
- /endpage
- { /pagenum pagenum 1 add def
- twinpage sheetside 0 eq and
- { /sheetside 1 def }
- { printpage }
- ifelse
- } bind def
-
- % Function sheetnumber: prints the sheet number.
- /sheetnumber
- { sheetnumberx sheetnumbery moveto
- datefont setfont
- sheet pnum cvs
- dup stringwidth pop (0) stringwidth pop sub neg 0 rmoveto show
- empty pnum copy pop
- } bind def
-
- % Function s: print a source line
- /s { gsave
- show
- grestore
- 0 bodyfontsize neg rmoveto
- } bind def
-